package fi.jpalomaki.claims.ui;

import java.sql.Types;
import java.util.Iterator;
import java.util.Map;

import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.jdbc.object.StoredProcedure;
import org.springframework.jdbc.core.SqlParameter;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SqlOutParameter;


public class EmpDaoJdbc extends SimpleJdbcDaoSupport 
{

    private JdbcTemplate jdbcTemplate;
    /*private EmployeeSP  sproc;
    public String getEmployeeName(int emp_id){ 
    	return (String) sproc.execute(emp_id); 
    	}*/

    
	/*public void setDataSource(DataSource source){ 
		this.jdbcTemplate = new JdbcTemplate(source); 
		this.sproc = new EmployeeSP(jdbcTemplate.getDataSource()); 
		}*/

    public String getAttrNamesProc()
    {
    	  //this.dataSource = dataSource;
		//
            String st = "";
            ProcedureAndFunctions stproc = new ProcedureAndFunctions();
            //jdbcTemplate=new SimpleJdbcCall(dataSource).withProcedureName("SALDO");
            stproc.setJdbcTemplate(getJdbcTemplate());
            stproc.setSql("SALDO");
            stproc.declareParameter(new SqlParameter("wartosc",Types.INTEGER));
            stproc.compile();
            Map results = stproc.execute();

            for (Iterator it = results.keySet().iterator(); it.hasNext();)
            {
                    System.out.println(results.get(it.next()));
            }
            return "0";
    }
    /*private class EmployeeSP extends StoredProcedure{ 
    	private static final String SPROC_NAME = "SALDO"; 
    	public EmployeeSP( DataSource datasource ){ 
    		super( datasource, SPROC_NAME ); 
    		declareParameter( new SqlParameter( "wartosc", Types.INTEGER) ); 
    		//declaring sql in parameter to pass input 
    		//declareParameter( new SqlOutParameter( "name", Types.VARCHAR ) ); 
    		//declaring sql out parameter 
    		compile(); } 
    		
    		public Object execute(int emp_id){ 
    			Map<String,Object> results = super.execute(emp_id); 
    			return "g";//results.get("name"); 
    			//reading output of stored procedure using out parameters } }
    	}
    }*/

    
}
